﻿<?php
require('../database/db.php');
$mysql=new mysql();
$result_data_array = array();
function check($filds,$msg){
	if(!$filds){
		$result_data_array['code'] = -100;
		$result_data_array['msg'] = $msg;
		echo json_encode($result_data_array);
		exit;
	}

}

$address=trim($_REQUEST[address]);//地址
$lon=trim($_REQUEST[lon]);//经度
$lat=trim($_REQUEST[lat]);//纬度
$head_pic = $_REQUEST['head_pic'];
$srcimages = $_REQUEST['srcimages'];
$images = $_REQUEST['images'];

$vr_dizhi = $_REQUEST['vr_dizhi'];
$wenzi_miaoshu = $_REQUEST['wenzi_miaoshu'];
$jiage_miaoshu = $_REQUEST['jiage_miaoshu'];
$classify=trim($_REQUEST[classify]);//分类
$zileimu=$_REQUEST[zileimu];//子分类
$city=trim($_REQUEST[city]);//城市
$name=trim($_REQUEST[name]);//商家名称
$tel=trim($_REQUEST[tel]);//登录账号
$alipay=trim($_REQUEST[alipay]);//支付宝账号
$aliname=trim($_REQUEST[aliname]);//支付宝收款人
$wechatpay=trim($_REQUEST[wechatpay]);//微信账号
$wechatname=trim($_REQUEST[wechatname]);//微信收款人
$content=trim($_REQUEST[content]);//商家简介
$phone=trim($_REQUEST[phone]); //商家电话
$password=trim($_REQUEST[password]);//密码
$start_price=trim($_REQUEST[start_price]);//起送价格
$distribution_fee=trim($_REQUEST[distribution_fee]);//配送费
$song_da=trim($_REQUEST[song_da]);//送达时间
$qq=trim($_REQUEST[qq]);
$huodong_miaoshu=trim($_REQUEST[huodong_miaoshu]);
$isKuaigou=trim($_REQUEST[isKuaigou]);
$isHaitao=trim($_REQUEST[isHaitao]);
$kgfanquan=trim($_REQUEST[kgfanquan]);
$htfanquan=trim($_REQUEST[htfanquan]);
$kgservice=trim($_REQUEST[kgservice]);
$htservice=trim($_REQUEST[htservice]);
$freight_ins=trim($_REQUEST[freight_ins]);
$licence=trim($_REQUEST[licence]);

$leimu = trim($_REQUEST['leimu']);
$zileimu = trim($_REQUEST['zileimu']);
$rate = trim($_REQUEST['rate']);
$groom_shop = trim($_REQUEST['groom_shop']);



check($tel,'商家注册异常');
check($password,'商家注册异常');
check($phone,'联系手机号不能为空');
check($name,'店铺名称不能为空');
check($phone,'联系手机号不能为空');
check($lon,'经纬度不能为空');
check($lat,'经纬度不能为空');
check($alipay,'支付宝账号');
check($aliname,'支付宝收款人不能为空');
check($wechatpay,'微信号不能为空');
check($wechatname,'微信收款人不能为空');
check($huodong_miaoshu,'活动描述不能为空');
check($wenzi_miaoshu,'商家标签不能为空');
check($jiage_miaoshu,'折扣描述不能为空');
check($city,'社区不能为空');
check($images,'商家主图不能为空');
check($srcimages,'商家主图不能为空');
check($head_pic,'头像不能为空');
check($leimu,'商家分类不能为空');
check($zileimu,'商家子分类不能为空');
check($licence,'营业执照不能为空');
check($qq,'qq不能为空');
check($groom_shop,'推荐商家代码不能为空');

//update的数组
$arr=array(
	'address'=>$address,
	'longitude'=>$lon,
	'latitude'=>$lat,
	'leimu'=>$classify,
	'zileimu'=>$zileimu,
	'city'=>$city,
	'name'=>$name,
	'licence'=>$licence,
	'tel'=>$tel,
	'alipay'=>$alipay,
	'alipay_name'=>$aliname,
	'weipay'=>$wechatpay,
	'weipay_name'=>$wechatname,
	'content'=>$content,
	'images'=>$images,
	'srcimages'=>$srcimages,
	'phone'=>$phone,
	'password'=>$password,
	'start_price'=>$start_price,
	'distribution_fee'=>$distribution_fee,
	'song_da'=>$song_da,
	'qq'=>$qq,
	'huodong_miaoshu'=>$huodong_miaoshu,
	'isKuaigou'=>$isKuaigou,
	'isHaitao'=>$isHaitao,
	'kgfanquan'=>$kgfanquan,
	'htfanquan'=>$htfanquan,
	'kgservice'=>$kgservice,
	'htservice'=>$htservice,
	'freight_ins'=>$freight_ins,
	'groom_shop'=>$groom_shop,
);

$table='shop';
$mysql->autoExecute($table,$arr);
$result=$mysql->insert_id();

$array=array();
if($result!=0&&$result!=''){

	$conn=mysql_connect('localhost','root','');
	mysql_select_db('xzpf');

	// 向e网生活的商家添加数据
	$query = mysql_query("INSERT INTO user (phone,password,userid,xzsh_shopid) VALUES ('$tel','$password','$result','$result')");
	$xzpf_userid = mysql_insert_id();
	// 向e网生活的商家添加数据 end

	$conn=mysql_connect('localhost','root','');
	mysql_select_db('xzsh');
	$query = mysql_query("UPDATE shop set xzpf_userid = ".$xzpf_userid." where shopid = ".$result);

	$result_data_array['code'] = 200;
	$result_data_array['msg'] = '成功';
	echo json_encode($result_data_array);
}else{
	$result_data_array['code'] = -100;
	$result_data_array['msg'] = '失败';
	echo json_encode($result_data_array);

}


?>